<?php

class VideoProcessor implements ISingleton 
{
	const RATE = '10';
	const BITRATE = '30';
	
	/**
     * @var Image_Replication
     */
    protected static $_instance = null;

    /**
     * @return Image_Replication
     */
    protected function __construct() {}

    /**
     * Returns an instance of Image_Replication
     * Singleton pattern implementation
     *
     * @return Image_Replication
     */
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
	
	
	public function getFrame($srcPath, $outPath)
	{
		$movie = new ffmpeg_movie($srcPath, false);
		if (!$movie) {
			throw new Exception('Unable to open movie');
		}
		$totalFrames = $movie->getFrameCount();
		$middleFrameNumber = intval($totalFrames/2);
		if ($middleFrameNumber <= 0) {
			return false;
		}
		$frame	= $movie->getFrame($middleFrameNumber);
		if ($frame) {
			$image = $frame->toGDImage();
			return imagepng($image, $outPath);
		} else {
			return false;
		}
	}
	
}